package com.btkjgc.utils;

import com.btkjgc.models.AdminUserRole;
 
import com.btkjgc.models.Dictionary;
import com.btkjgc.models.Role;
 
import com.btkjgc.service.impl.DictionaryService_Impl;
import com.btkjgc.service.intf.DictionaryService_Intf;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by HelloWorld on 2015/4/3.
 */
public final class DataDisplayUtil
{
	private static DictionaryService_Intf dictionaryService = new DictionaryService_Impl();

	public static String boolDisplay(Boolean b)
	{
		if (b == false) { return "关"; }
		return "开";
	}

	static SimpleDateFormat datetimeformat = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss");

	static SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");

	public static String toDateTime(Date value) {
		//System.out.println(value);
		if (value != null) {
			return datetimeformat.format(value);
		}
		return "无";
	}

	public static String toDate(Date value)
	{
		if (value != null) { return new SimpleDateFormat("yyyy年MM月dd日")
				.format(value); }
		return "";
	}

	public static String toStringDate(Date value)
	{
		return new SimpleDateFormat("yyyyMMddHHmmss").format(value);
	}

	static public String ToTwoPoint(Object obj)
	{
		if (obj == null)
		{
			return "0.00";
		}
		else
		{
			try
			{
				Double temp = Double.valueOf(obj.toString());
				if (temp >= 0)
				{
					temp += 0.005;
				}
				else if (temp < 0)
				{
					temp -= 0.005;
				}
				String str = temp.toString();
				int pIndex = str.indexOf(".");
				return str.substring(0, pIndex + 3);
			}
			catch (NumberFormatException e)
			{
				return obj.toString();
			}
		}
	}

	public static String floatFormat(float f)
	{
		return ToTwoPoint(f);

	}

	public static String dateFormat(Date d)

	{
		return new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒").format(d);
	}

	public static String dateToString(Date d)

	{
		return new SimpleDateFormat("yyyyMMddHHmmss").format(d);
	}

	public static String getRoleNameByAdminId(Integer adminId)
	{
		String auhql = "FROM AdminUserRole where userid=?";
		AdminUserRole aur = (AdminUserRole) HibernateUtil.executeQueryOneObject(auhql,
				new String[] { adminId.toString() });
		Integer roleid = 1;
		if (aur != null && aur.getRoleid() != null)
		{
			roleid = aur.getRoleid();
		}
		String hql = "FROM Role where id=?";
		Role role = (Role) HibernateUtil.executeQueryOneObject(hql,
				new String[] { roleid.toString() });
		return role.getName();
	}

	public static String isSend(Boolean send)
	{
		if (send)
		{
			return "是";
		}
		else
		{
			return "否";
		}

	}

	public static String is_gps(int i)
	{
		if (i == 0)
			return "不许超过";
		if (i == 1)
			return "允许超出，不限速";
		else
		{
			return "允许超出，限速";
		}

	}

	public static String is_timeout(int i)
	{
		if (i == 0)
			return "不允许";
		else
			return "允许";

	}

	public static String getTypeName(int i)
	{
		switch (i)
		{
		case 0:
			return "httpRequestType";
		case 1:
			return "CarType";
		case 2:
			return "CarWorkStatus";
		}
		return "";
	}

	public static String getType(int type, String name)
	{
		HashMap<String, String> map = dictionaryService.getDictoinaryByName( name);
		if (map.containsKey(type)) { return map.get(type); }
		return "";
	}

	public static List<String> getTypeList(String name)
	{
		return dictionaryService.getDictoinaryValuesByName(name);
	}

	public static Integer getKey(String value, String name)
	{
		return dictionaryService.getDictoinaryKeyByName(value,name);
	}

	public static List<Dictionary> getDictionary(String name)
	{
		List<Dictionary> dics = dictionaryService.getDictionaryByName(name);
		return dics;
	}

	static HashMap<Integer, String> stations = new HashMap<Integer, String>();

 

	static HashMap<Integer, String> entities = new HashMap<Integer, String>();

 

	 
}
